package com.ruoyi.web.member.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.member.domain.FamilyAudio;
import com.ruoyi.member.service.IFamilyAudioService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 家庭音频Controller
 * 
 * @author ruoyi
 * @date 2025-03-30
 */
@RestController
@RequestMapping("/member/audio")
public class FamilyAudioController extends BaseController
{
    @Autowired
    private IFamilyAudioService familyAudioService;

    /**
     * 查询家庭音频列表
     */
    @PreAuthorize("@ss.hasPermi('member:audio:list')")
    @GetMapping("/list")
    public TableDataInfo list(FamilyAudio familyAudio)
    {
        startPage();
        List<FamilyAudio> list = familyAudioService.selectFamilyAudioList(familyAudio);
        return getDataTable(list);
    }

    /**
     * 导出家庭音频列表
     */
    @PreAuthorize("@ss.hasPermi('member:audio:export')")
    @Log(title = "家庭音频", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FamilyAudio familyAudio)
    {
        List<FamilyAudio> list = familyAudioService.selectFamilyAudioList(familyAudio);
        ExcelUtil<FamilyAudio> util = new ExcelUtil<FamilyAudio>(FamilyAudio.class);
        util.exportExcel(response, list, "家庭音频数据");
    }

    /**
     * 获取家庭音频详细信息
     */
    @PreAuthorize("@ss.hasPermi('member:audio:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(familyAudioService.selectFamilyAudioById(id));
    }

    /**
     * 新增家庭音频
     */
    @PreAuthorize("@ss.hasPermi('member:audio:add')")
    @Log(title = "家庭音频", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FamilyAudio familyAudio)
    {
        return toAjax(familyAudioService.insertFamilyAudio(familyAudio));
    }

    /**
     * 修改家庭音频
     */
    @PreAuthorize("@ss.hasPermi('member:audio:edit')")
    @Log(title = "家庭音频", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FamilyAudio familyAudio)
    {
        return toAjax(familyAudioService.updateFamilyAudio(familyAudio));
    }

    /**
     * 删除家庭音频
     */
    @PreAuthorize("@ss.hasPermi('member:audio:remove')")
    @Log(title = "家庭音频", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(familyAudioService.deleteFamilyAudioByIds(ids));
    }
}
